package gui;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;

import javax.swing.*;

import util.ImageLoader;

import controller.camera.CameraSetting;

public class CameraControlPanel {

	private final CameraSetting camera;
	
	private boolean free = true;
	private ImageButton toggleButton;
	
	private final BufferedImage freeIcon;
	private final BufferedImage lockedIcon;
	
	public CameraControlPanel(CameraSetting camera) {
		this.camera = camera;
		
		ImageLoader loader = new ImageLoader("/resource/image/menu/");
		freeIcon = loader.load("cam.png");
		lockedIcon = loader.load("camLocked.png");
		
		toggleButton = new ImageButton(freeIcon);
		toggleButton.setMargin(new Insets(0, 0, 0, 0));
		this.camera.setMode(CameraSetting.FREE);
		
		toggleButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				toggleMode();
			}
		});
	}
	
	public JComponent getButton() {
		return toggleButton;
	}
	
	private void toggleMode() {
		free = !free;
		camera.setMode(free ? CameraSetting.FREE : CameraSetting.FOCUS_ON_OBJECT);
		
		if (free) {
			toggleButton.setImage(freeIcon);
		} else {
			toggleButton.setImage(lockedIcon);
		}
	}
	
}
